package game.gui 
{
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.utils.getQualifiedClassName;
	import game.core.phases.TurnPhase;
	import game.core.Player;
	import game.GameWorld;
	import game.gui.panels.player.*;
	import game.gui.panels.phase.*;
	import net.flashpunk.FP;
	/**
	 * ...
	 * @author Sulus Ltd.
	 */
	public class Gui extends Sprite
	{
		
		public var camera:Camera;
		public var papa:GameWorld;
		public var currentPanel:PlayerPanel;
		private var mc:MovieClip;
		
		public function Gui() 
		{
			mc = new gui_panel();
			addChild(mc);
		}
		
		public function Init(papa:GameWorld):void
		{
			this.papa = papa;
			camera = new Camera();
			papa.add(camera);
			
			
		}
		
		public function Die():void
		{
			papa.remove(camera);
		}
		
		public function Update():void
		{
			
		}
		
		public function ShowCurrentPhase(phase:TurnPhase):void
		{
			if (phase)
			{
				mc.phase_text.text = phase.name;
			} else
			{
				mc.phase_text.text = "ничего не происходит";
			}
		}
		
		public function ShowPlayerPanel(player:Player):void
		{
			var raceName:String = "";
			if (player)
			raceName = getQualifiedClassName(player.race);
			
			switch (raceName) 
			{
				case "game.core.races::DwarfRace":
				
					SetCurrentPanel(new DwarvenPanel(player));
				
				break;
				case "game.core.races::MageRace":
					
					SetCurrentPanel(new MagesPanel(player));
				
				break;
				default:
					SetCurrentPanel(null);
				break;
			}
		}
		
		private function SetCurrentPanel(panel:PlayerPanel):void 
		{
			if (currentPanel)
			{
				currentPanel.Die();
				currentPanel.papa = null;
				removeChild(currentPanel);
				currentPanel = null;
			}
			
			if (panel)
			{
				currentPanel = panel;
				addChild(currentPanel);
				currentPanel.papa = this;
				currentPanel.Init();
			}
		}
		
	}

}